package com.cw.controller;


import com.cw.annotation.ResultObjectAnnotation;
import com.cw.common.api.ResultObject;
import com.cw.common.constant.DmlTypeConstant;
import com.cw.constant.Constants;
import com.cw.entity.AuthorityPrehospital;
import com.cw.service.IAuthorityPrehospitalService;
import com.cw.util.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ly
 * @since 2021-09-03
 */
@Api(tags = {"院前准备权限"})
@RestController
@RequestMapping("/authority-prehospital")

public class AuthorityPrehospitalController {

    @Autowired
    private IAuthorityPrehospitalService targetService;


    @PostMapping("/save")
    @ApiOperation("新建")
    public ResultObject saveOrUpdate(@RequestBody AuthorityPrehospital AuthorityPrehospital) {
        boolean b = targetService.insertAuthorityPrehospital(AuthorityPrehospital);

        if (b) { return ResultObject.successReturn("创建成功!!"); }

        return ResultObject.errorReturn("已存在相应的权限,或者创建失败!!");
    }


    @GetMapping("/getById/{userId}")
    @ApiOperation("查看")
    @ResultObjectAnnotation(DmlTypeConstant.SELECT)
    public Object getById(@PathVariable String userId,Integer pageSize,Integer pageNum) {
        return targetService.getAuthorityPrehospitalbyUserId(userId, pageNum, pageSize);
    }

    @GetMapping("/getAccess")
    @ApiOperation("获取当前用户应有的权限")
    public ResultObject getAccess(@RequestParam String yard) {
        String userId = HttpUtil.getRequestHeaderInfo(Constants.USER_ID);
        return ResultObject.successReturn(targetService.getAuthorityPrehospitalbyUserId(userId, yard));
    }


    @GetMapping("/getAccessPageInfoVersion")
    @ApiOperation("获取当前用户应有的权限-分页版")
    public ResultObject getAccessPageInfoVersion(@RequestParam Integer pageNum, Integer pageSize, String userCode) {
        return ResultObject.successReturn(targetService.getAuthorityPrehospitalbyUserId(userCode, pageNum, pageSize));
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    @ResultObjectAnnotation(DmlTypeConstant.DELETE)
    public Object delete(@PathVariable String id) {
        return targetService.removeById(id);
    }

}

